//
//  ByCellMineConsume.m
//  chequanbao_ios
//
//  Created by mc on 2017/5/15.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellMineConsume.h"

@interface ByCellMineConsume()
{
    UIView   *_bgView;
    UILabel  *_shopLabel;
    UILabel  *_timeLabel;
    UILabel  *_priceLabel;
}

@end

@implementation ByCellMineConsume
+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellMineConsume";
    ByCellMineConsume *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    
    _bgView = [[UIView alloc] init];
    _bgView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.25];
    _bgView.layer.cornerRadius = 4.0;
    [self addSubview:_bgView];
    
    _shopLabel = [[UILabel alloc] init];
    _shopLabel.font = FONT(14);
    _shopLabel.textColor = [UIColor whiteColor];
    [_bgView addSubview:_shopLabel];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = FONT(12);
    _timeLabel.textColor = [UIColor colorWithWhite:0.90 alpha:1];
    [_bgView addSubview:_timeLabel];
    
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.font = FONT(14);
    _priceLabel.textColor = [UIColor yellowColor];
    [_bgView addSubview:_priceLabel];

}

// 我的消费记录
-(void)setConsume_model:(ByModelMineConsume *)consume_model{
    _consume_model = consume_model;
    
    // 背景视图
    CGFloat x,y,width,height;
    x = 10;
    y = 0;
    width = SCREEN_WIDTH - 2*x;
    height = 65;
    _bgView.frame = CGRectMake(x, y, width, height);
    
    // 价格
    NSString *str = [NSString stringWithFormat:@"-%@",_consume_model.price];
    width = [str getSizeOfString:14].width;
    height = 20;
    x = _bgView.width - width - 10;
    y = (65 - 20)/2;
    _priceLabel.frame = CGRectMake(x, y, width, height);
    _priceLabel.text = str;
    
    // 商家
    x = 10;
    y = 10;
    width = _bgView.width - 2*x - width;
    height = 20;
    _shopLabel.frame = CGRectMake(x, y, width, height);
    _shopLabel.text = _consume_model.shopName;
    
    // 时间
    x = 10;
    y = _shopLabel.bottom + 5;
    width = _bgView.width - 2*x - _priceLabel.width;
    height = 20;
    _timeLabel.frame = CGRectMake(x, y, width, height);
    _timeLabel.text = [NSString stringWithFormat:@"%@",[NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:[_consume_model.createTime  integerValue]]]];

}

// 我的车险金
-(void)setPoints_model:(ByModelMinePoints *)points_model{
    _points_model = points_model;
    // 背景视图
    CGFloat x,y,width,height;
    x = 10;
    y = 0;
    width = SCREEN_WIDTH - 2*x;
    height = 65;
    _bgView.frame = CGRectMake(x, y, width, height);
    
    // 价格
    NSString *str = [NSString stringWithFormat:@"%.2f",(_points_model.after_score.floatValue - _points_model.before_score.floatValue)/100.0];
    if (_points_model.change_type.integerValue == 2) {
        str = [NSString stringWithFormat:@"+%@",str];
    }
    width = [str getSizeOfString:14].width;
    height = 20;
    x = _bgView.width - width - 10;
    y = (65 - 20)/2;
    _priceLabel.frame = CGRectMake(x, y, width, height);
    _priceLabel.text = str;
    
    // 商家
    x = 10;
    y = 10;
    width = _bgView.width - 2*x - width;
    height = 20;
    _shopLabel.frame = CGRectMake(x, y, width, height);
//    _shopLabel.text = _points_model.phoneNumber;
//    NSMutableString *name = [NSMutableString stringWithString:_points_model.reason];
//    [name replaceCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
//    NSString *nameStr = [NSString stringWithFormat:@"推荐用户%@用户购买车险",name];
    _shopLabel.text = _points_model.reason;
    
    // 时间
    x = 10;
    y = _shopLabel.bottom + 5;
    width = _bgView.width - 2*x - _priceLabel.width;
    height = 20;
    _timeLabel.frame = CGRectMake(x, y, width, height);
    _timeLabel.text = [NSString stringWithFormat:@"%@",[NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:[_points_model.create_time  integerValue]]]];

}
@end
